/*
 * Copyright the original author or authors.
 * 
 * Licensed under the MOZILLA PUBLIC LICENSE, Version 1.1 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.mozilla.org/MPL/MPL-1.1.html
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
 package com.blitscreen.utils
{
	import flash.geom.Point;
	
	public class BlitUtils
	{
		static public function id2pos( i : Number, gridSize : Point ) : Point
		{
			return id2posW( i, gridSize.x );
		}		
		static public function id2posW( i : Number, gridWidth : Number ) : Point
		{
			var sx:Number = gridWidth;
			var x:Number = i % sx;
			var y:Number = ( i - x ) / sx;
			return new Point( x, y );
		}
	
		static public function pos2id( p : Point, gridSize : Point ) : Number
		{		
			var sx:Number = gridSize.x;
			return p.y * sx + p.x;
		}
		static public function pos2idXY ( x : Number, y : Number, gridSize : Point ) : Number
		{		
			var sx:Number = gridSize.x;
			return y * sx + x;
		}
	}
}